package com.kashi.controller;

import com.kashi.anno.Log;
import com.kashi.pojo.Dept;
import com.kashi.pojo.Result;
import com.kashi.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门管理Controller
 */
@Slf4j
@RestController
public class DeptController {

    //private static Logger log = LoggerFactory.getLogger(DeptController.class);

    @Autowired
    private DeptService deptService;

    //@RequestMapping(value = "/depts", method = RequestMethod.GET)//指定请求方式
    @GetMapping("/depts")
    public Result list(){
        log.info("查询全部团体信息");
        //调用service查询
        List<Dept> deptList = deptService.list();
        return Result.success(deptList);
    }


    @Log
    //删除团体
    @DeleteMapping("/depts/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("根据id删除团体：{}",id);
        //调用service删除
        deptService.delete(id);
        return Result.success();
    }


    @Log
    //新增团体
    @PostMapping("/depts")
    public Result add(@RequestBody Dept dept){
        log.info("新增团体：{}", dept);
        //调用service新增
        deptService.add(dept);
        return Result.success();
    }

}
